// const hello = require('@/mysql/index') // 测试全局引入
const {Project} = require('@/mysql/project')
const {ProjectType} = require('@/mysql/project_type')
const {User} = require('@/mysql/user')
const getAllProject = async ctx => {
    const {deleted, type_id, name} = ctx.query
    ctx.response.body = await User.getProject(deleted, type_id, name)
}
// 插入项目（添加项目）
const insertProject = async ctx => {
    if (ctx.request.body) {
        let {name, description, type_id} = ctx.request.body
        if (!name) return ctx.response.body = global.toJson(1, `缺少项目名称`)
        if (type_id) {
            const data = await ProjectType.findById(type_id);
           if(!data.length) return ctx.response.body = global.toJson(1, `没有找到该分类`)
        }
        const data = await Project.insertData(name, description, type_id)
        if (data) {
            ctx.response.body = global.toJson(0, '添加项目成功')
        }
    }
}
const getProjectById = async ctx => {
    const project_id = ctx.params.id
    if(!project_id) return ctx.body = global.toJson(1, '缺少项目Id')
    ctx.body = await Project.findOne({where: {project_id}})
}
export {getAllProject, insertProject, getProjectById}
